package controllers

import (
	"go-dingding/models"
	"fmt"
)

// DingDingController
type DingDingController struct {
	BaseController
}

// @Title Get
// @Success 200 "发送成功"
// @Param   DingDing query string
// @Param   Metric query string
// @Param   MetricAlarm query string
// @Failure 400 Param check failed
// @Failure 500 post DingDing common error
// @router / [Get]
func (c *DingDingController) Get() {
	var dingTalkModel models.DingTalkModel
    dingDing := c.GetString("DingDing")
    if dingDing != "" {
       if(dingDing == "alarm"){
            dingTalkModel.Metric = c.GetString("Metric")
            dingTalkModel.MetricAlarm = c.GetString("MetricAlarm")
            if err := models.SendDingtalk(&dingTalkModel); err == nil {
            	c.Ctx.Output.SetStatus(200)
            	c.Data["json"] = "钉钉告警信息发送成功!"
            } else {
            	c.Data["json"] = err.Error()
            }
       }else {
           c.Data["json"] = "参数不正确"
           fmt.Println("参数不正确")
       }
	}else {
     	c.Data["json"] = "参数不能为空"
     	fmt.Println("参数不能为空")
     	}
	c.ServeJSON()
}